package dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import dao.MissionsDao;
import pojo.MissionRelations;
import pojo.Missions;
import pojo.ProjectMissions;
import pojo.Teams;
import util.DateTransfrom;

/** 
* @author WuYuan
* 
*/
public class MissionsDaoImpl implements MissionsDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	
	public SqlSessionTemplate getSqlSessionTemplate() {
		return sqlSessionTemplate;
	}

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}

	
	@Override
	public List<Missions> findMissionsByUrpid(String projectid, String userid, String roleId) throws Exception {
		Object [] objects =new Object[]{projectid,userid,roleId};
		return sqlSessionTemplate.selectList("findMissionsByUrpid",objects);
	}
	
	@Override
	public List<ProjectMissions> findProjectMissionsByUrpid(String projectid, String roleid)throws Exception{
		Object [] objects =new Object[]{projectid,roleid};
		return sqlSessionTemplate.selectList("findProjectMissionsByUrpid",objects);
	};
	
	@Override
	public int updateMissionsToCompleted(String missionid) throws Exception {
		Missions updatemission = new Missions();
		updatemission.setMissionid(Integer.parseInt(missionid));
		updatemission.setAft(DateTransfrom.getSystemDate());
		System.out.println("daoimpl的missionid是"+missionid+DateTransfrom.getSystemDateStr());
		return sqlSessionTemplate.update("updateMissionsToCompleted",updatemission);
	}
	
	@Override
	public List<MissionRelations> findPMRelationsByUrpid(String projectId,String roleId)throws Exception{
		Object [] objects =new Object[]{projectId,roleId};
		return sqlSessionTemplate.selectList("findPMRelationsByUrpid",objects);
	}

	@Override
	public Missions findMissionsByMissionid(String missionid) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("查找对应missionid"+missionid);
		return (Missions)sqlSessionTemplate.selectOne("findMissionsByMissionid",missionid);
	}

	@Override
	public int updateObjectivescore(String missionid) throws Exception {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("updateObjectivescore",missionid);
	}

	@Override
	public List<Teams> findTeamsByUrpid(String userid) throws Exception {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("findTeamsByUrpid",userid);
	}

	@Override
	public List<ProjectMissions> findProjectMissionsIsCPByUrpid(String projectid, String roleid) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("获取已完成阶段任务所需的projectid和roleid分别是"+projectid+"和"+roleid);
		Object [] objects =new Object[]{projectid,roleid};
		System.out.println("111111111");
		return sqlSessionTemplate.selectList("findProjectMissionsIsCPByUrpid",objects);
	}

	@Override
	public List<Missions> findAllMissionsByMissionid(String missionid) throws Exception {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("findAllMissionsByMissionid",missionid);
	}

	@Override
	public int updateProjectMissionsToCompleted(String missionid) throws Exception {
		// TODO Auto-generated method stub
		Object [] objects =new Object[]{missionid,DateTransfrom.getSystemDate()};
		return sqlSessionTemplate.update("updateProjectMissionsToCompleted",objects);
	}


}
